package com.InteInfo.common.email;

import org.apache.log4j.Logger;

public class SendEmailClient {

	private static final Logger logger = Logger
			.getLogger(SendEmailClient.class);

	public static void Send(String Host, String[] FromAddress,
			String[] ToAddress, String Subject, String Content,
			String[] FileAddress) {

		SendMail mail = new SendMail();
		MailInfo mailInfo = new MailInfo();

		// 设置邮件服务器，这里暂时用126邮箱服务器,拓展的话以后可以用上面的形参Host配置
		// mailInfo.setHost(Host);
		mailInfo.setHost("smtp.126.com");
		// 设置邮件发件人，这里的发件人也是固定的，拓展的话可以用上面的形参FromAddress配置
		mailInfo.setFromAddress("servicemessage@126.com");
		mailInfo.setUsername("servicemessage@126.com");
		mailInfo.setPassword("zhujie1392352985");

		// mailInfo.setFromAddress(FromAddress[0]); 发件人地址
		// mailInfo.setUsername(FromAddress[0]); 发件人姓名
		// mailInfo.setPassword(FromAddress[1]); 发件人密码

		// 设置为是否校验
		mailInfo.setValidate("true");
		// 设置邮件主题
		mailInfo.setSubject(Subject);
		// 设置邮件内容
		mailInfo.setContent(Content);
		// 设置邮件接收者，当收件人大于0的时候发给收件人，当收件人小于或等于0，发给服务器邮件
		if (ToAddress.length > 0) {
			mailInfo.setSendAddress(ToAddress);
		} else {
			ToAddress[0] = "servicemessage@126.com";
			mailInfo.setSendAddress(ToAddress);
		}
		if (FileAddress != null && FileAddress.length > 0) {
			mailInfo.setFilepath(FileAddress);
		}
		try {
			boolean flag = mail.Send(mailInfo);
			if (flag == true) {
				logger.info(mailInfo.getSubject() + ":发送成功");
			} else {
				logger.info(mailInfo.getSubject() + ":发送失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
		}
	}
}
